package edu.sias.course.controller;


import edu.sias.common.core.controller.BaseController;
import edu.sias.course.domain.dto.CatalogDTO;
import edu.sias.course.domain.entity.CatalogPageQueryParams;
import edu.sias.course.domain.entity.PageResult;
import edu.sias.course.domain.entity.QueryPageBean;

import edu.sias.course.service.CatalogService;
import edu.sias.common.core.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Description CatalogController
 * @Author liu
 * @Date
 */
@RestController
@RequestMapping("/course/catalog")
@Slf4j
@Api(tags = "学科目录相关接口")
public class CatalogController extends BaseController {

    @Resource
    private CatalogService catalogService;

    @ApiOperation("学科目录添加接口")
    @PostMapping("/add.do")
    public AjaxResult add(@RequestBody CatalogDTO catalogDTO){

        log.info("执行添加学科目录操作：{}",catalogDTO);
        //调用service添加学科目录
        catalogService.add(catalogDTO);

        //返回数据
        return AjaxResult.success("添加学科目录成功");
    }

    @ApiOperation("学科目录分页列表接口")
    @PostMapping("/findListByPage.do")
    public AjaxResult findListByPage(
            @RequestBody QueryPageBean<CatalogPageQueryParams> queryPageBean){
        log.info("执行添加学科目录分页列表操作：{}",queryPageBean);
        PageResult pageResult = catalogService.findListByPage(queryPageBean);
        return AjaxResult.success(pageResult);
    }

    @ApiOperation("学科目录删除接口")
    @GetMapping("/delete.do")
    public AjaxResult delete(Integer catalogId){
        log.info("执行删除学科目录操作：{}",catalogId);
        //调用service删除
        catalogService.delete(catalogId);
        //返回数据
        return AjaxResult.success(null,"学科目录删除成功");
    }

    @ApiOperation("学科目录更新接口")
    @PostMapping("/update.do")
    public AjaxResult update(@RequestBody CatalogDTO catalogDTO){
        log.info("开始执行学科目录更新接口：{}",catalogDTO);

        //调用service方法实现更新
        catalogService.update(catalogDTO);

        return AjaxResult.success("学科目录更新成功");
    }


}
